package org.option.testsuite.instruments.math_utils;

import com.alibaba.fastjson.JSONObject;
import org.option.testsuite.instruments.exception.ParamException;
import org.option.testsuite.instruments.pricing_env.DividenRate;
import org.option.testsuite.instruments.pricing_env.RiskFreeInterest;
import org.option.testsuite.instruments.pricing_env.Voliatility;

import java.util.HashMap;
import java.util.Map;

public class ParamFactory {
    private static final Map<Integer, Fd_Params> map = new HashMap<Integer, Fd_Params>();
    static {
        map.put(1,new Fd_Params(new Voliatility((double) 0.15),new DividenRate((double) 0.04),new RiskFreeInterest((double) 0.01)));
        map.put(2,new Fd_Params(new Voliatility((double) 0.20),new DividenRate((double) 0.05),new RiskFreeInterest((double) 0.02)));
        map.put(3,new Fd_Params(new Voliatility((double) 0.25),new DividenRate((double) 0.05),new RiskFreeInterest((double) 0.03)));
/*        map.put(1,new Fd_Params(new Voliatility(0.15),new DividenRate(0.04),new RiskFreeInterest(0.01)));
        map.put(2,new Fd_Params(new Voliatility(0.20),new DividenRate(0.05),new RiskFreeInterest(0.02)));
        map.put(3,new Fd_Params(new Voliatility(0.25),new DividenRate(0.05),new RiskFreeInterest(0.03)));*/
    }
    private static ParamFactory paramFactory = new ParamFactory();
    private double stageLength = (double) (2000/2.0)+1;
    private ParamFactory(){}
    public static ParamFactory getInstance(){
        return paramFactory;
    }
    public Fd_Params getParam(double j)  throws ParamException {
        return getParamOfStageX(Double.valueOf(j/stageLength).intValue());
    }
    private Fd_Params getParamOfStageX(int x) throws ParamException{
        if(x < 0 || x > 2){
            throw new ParamException();
        }
        return map.get(Integer.valueOf(x)+1);
    }

    public static void main(String[] args){

        try {
            ParamFactory factory = ParamFactory.getInstance();
            System.out.println("test case 0 (1 excepted):" + JSONObject.toJSONString(factory.getParam(0)));
            System.out.println("test case 60.3 (1 excepted):" + JSONObject.toJSONString(factory.getParam((Double) 60.3)));
            System.out.println("test case 60.8 (2 excepted):" + JSONObject.toJSONString(factory.getParam((double) 60.8)));
            System.out.println("test case 121.3 (2 excepted):" + JSONObject.toJSONString(factory.getParam((double) 121.3)));
            System.out.println("test case 121.6 (3 excepted):" + JSONObject.toJSONString(factory.getParam((double) 121.6)));
            System.out.println("test case 181.3 (3 excepted):" + JSONObject.toJSONString(factory.getParam((double) 181.3)));
        }catch (Exception e){
            e.printStackTrace();

        }
    }
}
